package salary;

import java.util.ArrayList;
import java.util.List;

public class getSalary {
    java.sql.Connection conn = null;
    java.sql.Statement sqlStmt = null;
    java.sql.ResultSet sqlRst = null;
    public List getSalary()
    {
        List<salaryBean> list = new ArrayList<>();
        try{
            Class.forName("org.h2.Driver");
            conn = java.sql.DriverManager.getConnection("jdbc:h2:~/jpa-demo-db;MODE=MYSQL;DB_CLOSE_DELAY=-1", "sa", "sa");
            sqlStmt = conn.createStatement();
            String sql = "select manager.mno,pno,name,phone,salary,sex from manager,salary where salary.mno = manager.mno";
            sqlRst=sqlStmt.executeQuery(sql);
            while(sqlRst.next())
            {
                salaryBean sb = new salaryBean();
                sb.setMno(sqlRst.getString("mno"));
                sb.setName(sqlRst.getString("name"));
                sb.setPno(sqlRst.getString("pno"));
                sb.setSalary(sqlRst.getString("salary"));
                sb.setSex(sqlRst.getString("sex"));
                sb.setPhone(sqlRst.getString("phone"));
                list.add(sb);
            }

        }catch(Exception ex)
        {
            System.out.println(ex.toString());
        }
        return list;
    }
}
